$(function() {
	//弹出模态框
	var editDom = $("#edit");
	var modalBox = $("#modalBox");
	editDom.click(function() {
		layer.open({
			title:'福利待遇',
			type: 1,
			area: ['500px'],
			btn:["确认","取消"],
			content: $('#modalBox'),
			yes:function(index, layero){
				if($('.welfare .right .lable')) {
					$('.welfare .right .lable').remove();
				}
			    var avtiveDom = $('.modal-box .modal-container .lables .active');
			    var lableArray = [];
			    for(var i = 0;i < avtiveDom.length;i++) {
			    	lableArray[i] = avtiveDom.eq(i).html();
			    	editDom.before('<span class="lable">'+ lableArray[i] +'</span>');
			    }
			    
			    // 设置对应隐藏文本框的值
			    $('#treatment').val(lableArray.join(','));
			    
			    layer.close(index);
			},
		});
	})
	
	//模态框选择标签
	$(document).on('click', '.modal-box .modal-container .lables li', function() {
		$(this).toggleClass("active");
	});
	
	var customLable = $("#customLable");
	var ulDom = $(".modal-box .modal-container .lables");
	$("#addLable").click(function() {
		var customLableHtml = customLable.val();
		if(customLableHtml != ""){
			ulDom.append('<li>' + customLableHtml + '</li>');
			customLable.val('');
		}
	});
	
	// 选择省显示对应的城市
	$('#provinceUl li').click(function() {
		var provinceCode = $(this).data('value');
		var param = {
			provinceCode: provinceCode,
			time: new Date().getTime()
		}
		$.get(window.ctx + '/company/Company/listCities.action', param, function(result) {
			var $cityUl = $('#cityUl');
			$cityUl.empty();
			for (var i = 0; i < result.length; i++) {
				$cityUl.append('<li data-value="' + result[i].code + '">'+ result[i].name +'</li>');
			}
		}, 'json');
	})
	
	// 下拉选择时，设置对应隐藏的input的value
	$('.dropdown .option').on('click', 'li', function() {
		var value = $(this).data('value');
		$(this).parent().parent().next('input').val(value);
	});
})
